home *** CD-ROM | disk | FTP | other *** search
- /* AuxWindow.c */
- /*
- * AuxWindow
- * Superclass: CDirector.
- * Copyright © 1991 Martin Minow. All Rights Reserved.
- * All use and non-commercial distribution permitted.
- * Set tabs every 4 bytes.
- *
- * This class implements a generic auxiliary window that
- * may be used in addition to the document's normal
- * window. It is based on the CClipboard class.
- */
-
- #ifdef DOCUMENTATION
-
- Title AuxWindow
- Superclass CDirector
- Subclasses TextWindow
-
- usage
-
- #include "AuxWindow.h"
-
- void IAuxWindow(
- CApplication *aSupervisor,
- short aWindowId,
- Boolean isFloating,
- Boolean hideOnSuspend,
- long toggleCmd,
- short showHideRes
- );
- Initialization. itsSupervisor must be the
- application. It displays the window defined
- by aWindowId. See the description of CWindow
- for information on floating windows.
-
- hideOnSuspend is TRUE if this window should follow
- the Macintosh human interface guidelines, which
- recommend that floating windows and general status
- windows be hidden when your application is suspended.
- Set it FALSE if this window should remain visible
- except when the user explicitly hides it via the
- menu command (Toggle method) or by clicking in
- the close box.
-
- toggleCmd is the command number your application
- uses to make the window visible and invisible.
- If you don't have a show/hide menu command, just
- pass cmdNull and set showHideRes to zero. Otherwise,
- your application class should create a menu item
- using some variant on the following sequence:
-
- Str255 work;
- short MENUid;
- MenuHandle macMenu;
- short itemNo;
-
- GetIndString(work, itsMenuNames, kShowAuxWindow);
- gBartender->FindMenuItem(
- cmdToggleClip,
- &MENUid,
- &macMenu,
- &itemNo
- );
- if (macMenu != NULL && work[0] != 0) {
- gBartender->InsertMenuCmd(
- CmdToggleAuxWindow,
- work,
- MENUid,
- itemNo
- );
- }
-
- The above sequence creates a menu item that resides
- just below the Toggle Clipboard menu item. You can
- also just add the menu item to your resource file.
-
- showHideRes identifies a STR# resource containing:
- Show Status Window
- Hide Status Window
-
- These menu items will be added to the menu bar
- just after the Show/Hide clipboard menu command.
-
- Your application class DoCommand method should
- recognize the toggleCmd and send a Toggle message
- to the TextWindow:
-
- MyApp::DoCommand(
- long theCommand
- )
- {
- switch (theCommand) {
- case CmdToggleAuxWindow:
- myAuxWindow->Toggle();
- break;
- ...
- }
-
- Your application class must also enable the
- toggle command it its UpdateMenus method:
-
- MyApp::UpdateMenus()
- {
- inherited::UpdateMenus();
- gBartender->EnableCmd(CmdToggleAuxWindow);
- }
-
- void Dispose(void);
- Dispose of the window. Actually, AuxWindow doesn't
- have its own Dispose method: the CDirector
- Dispose will free the visual hierarchy and other
- local structures.
-
- void SetTitle(
- StringPtr aString
- );
- Set the AuxWindow title:
- myAuxWindow->SetTitle(macSFReply->fName);
-
- void Show(void);
- void Hide(void);
- void Toggle(void);
- Your application calls Toggle() to show or hide
- the window. By default, the window is created
- invisibly. Show() and Hide() explicitly set the
- window's visibility.
-
- Support Classes
-
- void Suspend(void);
- void Resume(void);
- These override the default classes. They hide
- when the application is suspended, and show it
- when the application is resumed (assuming it
- was visible, of course and hideOnSuspend was
- set when the window was created).
-
- void Close(
- Boolean quitting
- );
- void CloseWind(
- CWindow *theWindow
- );
- These override the standard classes so the window
- is hidden when closed, rather than deleted.
-
-
- window definition
-
- The window is defined by resources as follows:
-
- *
- * The AuxWindow Window
- *
- Type WIND
- Text Box, 1024 ;; WIND_AuxWindow
-
- 40 40 236 361
- InVisible GoAway
- 4 ;; noGrowDocProc
- 0
-
- *
- * The AuxWindow menu commands
- *
- Type STR#
- Text Box, 1024 ;; STRS_AuxWindow
- 2
- Show Status Window
- Hide Status Window
-
-
- Author
- Martin Minow
-
- Copyright
- Copyright © 1991 Martin Minow. All Rights Reserved.
- Non-commercial use and distribution permitted.
-
- #endif
-
- #include <CBartender.h>
- #include <CDesktop.h>
- #include <Commands.h>
- #include "AuxWindow.h"
-
- extern CBartender *gBartender;
- extern CBureaucrat *gGopher;
- extern CDesktop *gDesktop;
- extern Boolean gInBackground;
-
- /*
- * Initialize the AuxWindow. A director consists of a
- * visual hierarchy (CWindow and CPanes) along with a
- * control hierarchy. In this case, there really isn't
- * a unique control hierarchy: all of the standard "move
- * window" operations are handled by the TCL classes. All
- * we need to do here is to create the window and data
- * panes. In order to support hiding and revealing the
- * window, the application needs a Toggle Status Window
- * command and a STR# resource with two strings:
- * Show Status Window
- * Hide Status Window
- */
- void
- AuxWindow::IAuxWindow(
- CApplication *aSupervisor,
- short aWindowId,
- Boolean isFloating,
- Boolean isHiddenOnSuspend,
- long toggleCmd, /* Our command */
- short showHideRes /* STR# text */
- )
- {
- /*
- * Initialize the superclass.
- */
- CDirector::IDirector(aSupervisor);
- /*
- * Next, create and position the window.
- */
- itsWindow = new(CWindow);
- itsWindow->IWindow(
- aWindowId, /* A noGrowDocProc */
- isFloating, /* Maybe floating */
- gDesktop,
- this
- );
- hideOnSuspend = isHiddenOnSuspend;
- itsToggleCmd = toggleCmd;
- itsMenuNames = showHideRes;
- windowVisible = FALSE;
- #if 0
- /*
- * Your sub-class may want to position the
- * window and create it visibly. If so,
- * add the following (or whatever is appropriate)
- * to your initialization method.
- */
- gDecorator->CenterWindow(itsWindow);
- Show();
- #endif
- }
-
- /*
- * The SetTitle method sets the window's title bar. Note
- * that an application that uses the AuxWindow dosen't know
- * that the title is going to a window -- or even that
- * there is a window. I.e. you could easily turn the
- * AuxWindow class into a printing or file-logging class.
- */
- void
- AuxWindow::SetTitle(
- StringPtr aTitle
- )
- {
- itsWindow->SetTitle(aTitle);
- }
-
- /*
- * The Suspend, Resume, Close, and CloseWind methods
- * override their CDirector counterparts in order to
- * permit hiding and revealing the AuxWindow window
- * without destroying it. Your application (or some other
- * class) must respond to the CmdToggle command by calling
- * the Toggle() method. The original idea for this was
- * taken from the TCL CClipboard class.
- */
-
- void
- AuxWindow::Suspend()
- {
- if (windowVisible) {
- if (hideOnSuspend == FALSE)
- itsWindow->HideSuspend();
- if (active) {
- itsWindow->Deactivate();
- active = TRUE;
- }
- }
- }
-
- void
- AuxWindow::Resume()
- {
- if (windowVisible) {
- if (hideOnSuspend == FALSE)
- itsWindow->ShowResume();
- if (active) {
- itsWindow->Activate();
- gGopher = this;
- }
- }
- }
-
- /*
- * Close the AuxWindow by hiding it. We don't care if the
- * application is quitting or not.
- */
- Boolean
- AuxWindow::Close(
- Boolean quitting
- )
- {
- if (windowVisible) {
- if (gInBackground)
- itsWindow->ShowResume();
- CloseWind(itsWindow);
- }
- return (TRUE);
- }
-
- /*
- * The user (probably) clicked in the close box --
- * or we're here because visiblity was toggled.
- * just close the window and fix the menu.
- */
- void
- AuxWindow::CloseWind(
- CWindow *theWindow
- )
- {
- Str255 work;
-
- theWindow->Hide();
- windowVisible = FALSE;
- Deactivate();
- if (itsToggleCmd != cmdNull) {
- GetIndString(
- work, itsMenuNames, kShowAuxWindow);
- gBartender->SetCmdText(itsToggleCmd, work);
- }
- }
-
- void
- AuxWindow::Hide()
- {
- if (windowVisible)
- CloseWind(itsWindow);
- }
-
- void
- AuxWindow::Show()
- {
- Str255 work;
-
- if (windowVisible == FALSE) {
- itsWindow->Select();
- windowVisible = TRUE;
- if (itsToggleCmd != cmdNull) {
- GetIndString(
- work, itsMenuNames, kHideAuxWindow);
- gBartender->SetCmdText(itsToggleCmd, work);
- }
- /*
- * If the application enabled floating windows,
- * this window will be created "deactivated"
- * because an unwanted deactivate event is
- * stuffed -- somehow -- into the event queue.
- * I don't really understand this, so don't be
- * suprised if it turns out to be a bug.
- */
- if (CurDeactive == itsWindow->GetMacPort())
- CurDeactive = NULL;
- }
- }
-
- /*
- * Toggle the window visiblity. If it was invisible (or
- * newly created), set the menu command.
- */
- void
- AuxWindow::Toggle()
- {
- if (windowVisible)
- Hide();
- else {
- Show();
- }
- }
-